<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加米线</title>
    <link rel="stylesheet" href="/public/admin/css/layui.css"  media="all">
    <script src="/public/index/css/jquery.min.js"></script>
    <style>

    </style>
</head>
<body class="layui-layout-body">
<div style="height: 30px; width: 100%;"></div>
<form class="layui-form" style="padding-right: 40px;">
    <div class="layui-form-item">
        <label class="layui-form-label">米线名称</label>
        <div class="layui-input-block">
            <input type="text" name="f_name" required  lay-verify="required" placeholder="请输入米线名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">价格</label>
        <div class="layui-input-inline">
            <input type="text" name="f_price" required lay-verify="required" placeholder="请输入价格" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">元</div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">米线描述</label>
        <div class="layui-input-block">
            <textarea id="marks" name="f_marks" placeholder="请输入米线描述" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <div class="layui-input-block">
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="test1">上传缩略图</button>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo1" width="100">
                <p id="demoText" style="width: 100px; height: 100px; border: 1px solid #f2f2f2;"></p>
            </div>
        </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">添加米线</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="/public/admin/layui.all.js" charset="utf-8"></script>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            //layer.msg(JSON.stringify(data.field));
            var f_name=$("input[name='f_name']").val();
            var f_price=$("input[name='f_price']").val();
            var f_marks=$("#marks").val();
            var f_img="/public/uploadimg/002.jpg";

            $.post("/admin_addricem_do", {f_name:f_name,f_price:f_price,f_marks:f_marks,f_img:f_img}, function (result) {
                if (result == 200) {
                    layer.msg("米线添加成功");
                    window.parent.location.reload();
                } else {
                    layer.msg("米线添加失败");
                }
            });
            return false;
        });
    });
</script>


<script>
    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/admin_addricem_img'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });



    });
</script>


</body>
</html>